26. [Optional] Cars and Probability

Cars and Probability

Before you start programming your own self-driving car, having a solid foundation in probability will be very important. Probability is used to analyze sensor data, predict future events, and make decisions. Below we will explore the foundation of probability to aid you on your journey to be a self-driving car engineer!

** If you are already comfortable with basic probability, please feel free to skip these exercises. **

Combinatorics (i.e. counting)

Combinatorics 1

Suppose you are driving your car (B) and you reach a T-intersection depicted above.

What are the possible directions you can legally turn?

SOLUTION:
  • Left
  • Right

Combinatorics 2

Referencing the previous questions, how many directions can you legally turn?

SOLUTION: 2

Combinatoricss 3

Now, let us suppose you are in a self-driving car. Turning in either direction is fine, but you can’t turn in both directions at once. How many ways can you turn left?

SOLUTION: 1

Probability

Now that you have built your sample space and understand the mechanics, it is time to move into some probability.

Probability can typically be thought of as:

\Large \frac {\textrm {Number of ways an event can occur}}{\textrm{Total number of events that could occur}}

An "event" is defined as some type of state that can happen. For example, turning "left" or "right" are both events. Similarly, pressing the "gas" or "brake" are also events. All probabilities will be between 0 and 1 inclusive.

If a probability is ever negative or larger than one, there is something wrong with the calculation, so please double-check the answer.

Often, the notation P(X) is used. This typically means the probability of "X" occuring. "X" is just a placeholder, but a more specific example will be provided below.

Probability 1

QUESTION:

Using the definition above, how many ways can the car turn left out of all the scenarios? In other words, what is P(Left turn)?

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

Probability 2

QUESTION:

What is P(Right Turn)?

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

Adding Probabilities (i.e. using "or" )

Probability "or"

QUESTION:

When we discuss probability, the use of the word “or” means we sum probabilities. What is the probability we go left or right?

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

Compliments

Often in probability, there will be a time when you want to know the result of a specific event. Unfortunately, sometimes, this event can be really tricky to calculate. However, it may be really easy to calculate all other events except this event. By doing this, we can exploit the following property:

\textrm{Specific outcome = 1 - (The sum of probability of all other events)}

This will yield the probability for the event in question.

Probability Compliment

QUESTION:

Assume that taking a right will get the self-driving car to the destination faster (and safer) than taking a left. As a result, the car prefers taking right with a P(Right Turn) = 0.8.

What is P(Left Turn)?

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

Multiplying Probabilities (i.e. using "and")

When dealing with probabilities, sometimes outcomes can be independent of each other - meaning, a previous outcome does not change the probability for the current outcome. Usually, when dealing two more events occurring, the word “and” is used. If “and” is used, this implies that the probabilities are multiplied instead of added.

Multiplying Probabilities

QUESTION:

Let’s assume a car can make a left with a probability of 0.2 and a right with a probability of 0.8. What is the probability the car makes a left and a left again (again as we declared earlier the second turn is an independent action from the first one, i.e. no additional information needed)?

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer

All Outcomes

It has been shown that independent events can be multiplied together. We will build on this concept below.

All Outcomes

QUESTION:

Staying with the theme of independent events and using the same numbers as above, what is the sum of the following probabilities? Leave your answer in decimal.

P(Left) * P(Left)

P(Left) * P(Right)

P(Right) * P(Left)

P(Right) * P(Right)

SOLUTION:

NOTE: The solutions are expressed in RegEx pattern. Udacity uses these patterns to check the given answer